import sys
import os

sys.path.append(os.path.abspath(os.path.join(__file__, '../..')))

from backend.experiment.framework.perplexity_calculator import \
    PerplexityCalculator
from backend.experiment.pangu.model import model
from backend.experiment.pangu.tokenizer import tokenizer

calculator = PerplexityCalculator(model)
while True:
    inputs = input('文本：')
    inputs = tokenizer.tokenize(inputs)
    inputs = calculator.model.format_inputs(inputs)
    print('ppl:', calculator.perplexity(inputs))
